<?php

require_once ('includes/functions/general.php');
require_once ('includes/functions/dal.php');
require_once ("includes/functions/facebookinclude.php");


function saveUser($uid, $name, $email)
{
    $user = new User();
    $user->setUid($uid);
    $user->setName($name);
    $user->setEmail($email);

    $userDal = new UserDal();
    return $userDal->save($user);
}

header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
//session_start();
$queryParam = '';
$imgName = '';

if (empty($_COOKIE['login']))
{
    #setcookie for login
    setcookie("login", "1", 0);

    $auth_url = "http://www.facebook.com/dialog/oauth?client_id=" . APP_ID .
        "&redirect_uri=" . urlencode(FACEBOOK_CANVAS_URL) .
        "&scope=publish_stream,email";
    echo ("<script type='text/javascript'> top.location.href='" . $auth_url .
        "';</script>");
    exit;
} else
{
    #setcookie for login
    setcookie("login", "", 0);
    require_once ("includes/functions/facebookinclude.php");
}

    $mainUser = saveUser($user["id"], $user["name"], $user["email"]);
    $_SESSION["user"] = $mainUser;
tep_redirect('quizz2.php?qNum=1');

?>
<head>
<base target="_top"/>
</head>